<?php
  class Helpers{
    public static function customDate($date)
    {
      $value = date('d F Y g:i A', strtotime($date));
      return $value;
    }
    
    public static function diff($start,$end = false){
      // Checks $start and $end format (timestamp only for more simplicity and portability) 
      if(!$end) { $end = time(); } 
      if(!is_numeric($start) || !is_numeric($end)) { return false; } 
      // Convert $start and $end into EN format (ISO 8601) 
      $start  = date('Y-m-d H:i:s',$start); 
      $end    = date('Y-m-d H:i:s',$end); 
      $d_start    = new DateTime($start); 
      $d_end      = new DateTime($end); 
      $diff = $d_start->diff($d_end); 
      // return all data 
      $this->year    = $diff->format('%y'); 
      $this->month    = $diff->format('%m'); 
      $this->day      = $diff->format('%d'); 
      $this->hour     = $diff->format('%h'); 
      $this->min      = $diff->format('%i'); 
      $this->sec      = $diff->format('%s'); 
      return true; 
    } 
    
    public static function remove_http($url = '')
    {
      return(str_replace(array('http://','https://'), '', $url));
    }

    public static function array_sort($array, $on, $order='SORT_ASC')
    {
        $new_array = array();
        $sortable_array = array();

        if (count($array) > 0) {
            foreach ($array as $k => $v) {
                if (is_array($v)) {
                    foreach ($v as $k2 => $v2) {
                        if ($k2 == $on) {
                            $sortable_array[$k] = $v2;
                        }
                    }
                } else {
                    $sortable_array[$k] = $v;
                }
            }

            switch ($order) {
                case 'SORT_ASC':
                    asort($sortable_array);
                break;
                case 'SORT_DESC':
                    arsort($sortable_array);
                break;
            }

            foreach ($sortable_array as $k => $v) {
                $new_array[$k] = $array[$k];
            }
        }

        return $new_array;
    }
  }
?>